package net.jueb.frameworkDemo.mq.rabbitMq;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;  
import com.rabbitmq.client.Connection;  
import com.rabbitmq.client.ConnectionFactory;  
  
public class Send  
{  
    //队列名称  
    private final static String QUEUE_NAME = "hello";  
  
    public static void main(String[] argv) throws java.io.IOException, TimeoutException  
    {  
        /** 
         * 创建连接连接到MabbitMQ 
         */  
        ConnectionFactory factory = new ConnectionFactory();  
        //设置MabbitMQ所在主机ip或者主机名  
        factory.setHost("192.168.0.205");  
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin");
        //创建一个连接  
        Connection connection = factory.newConnection();
        //创建一个频道  
        Channel channel = connection.createChannel();  
        //指定一个队列  
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);  
        //发送的消息  
        for(int i=0;i<10000;i++)
        {
        	String message = "hello world!-"+i;
        	//往队列中发出一条消息  
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); 
            System.out.println(" [x] Sent '" + message + "'");  
            try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
        }
        //关闭频道和连接  
        channel.close();  
        connection.close();  
     }  
}  